package com.shy.portal.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.shy.base.service.impl.BaseServiceImpl;
import com.shy.portal.dao.SysDictionaryDao;
import com.shy.portal.entity.SysDictionary;
import com.shy.portal.service.SysDictionaryService;

/**
 * <p>Title:SysDictionaryServiceImpl
 * <p>Description: 字典service
 * @author H2013788
 * @date 2020年3月12日
 */
@Service("sysDictionaryService")
@Transactional(readOnly=true)
public class SysDictionaryServiceImpl extends BaseServiceImpl<SysDictionary> implements SysDictionaryService {
	

    /**
     * dao层
     */
    @Resource
    private SysDictionaryDao sysDictionaryDao;

    @Resource
    private void setBaseDao(SysDictionaryDao sysDictionaryDao) {
        this.baseDao = sysDictionaryDao;
    }
    
	/**
	 * 方法描述: 字典生成下拉数据 通用
	 * 
	 * @Return
	 **/
	public List<SysDictionary> getDictByType(String dictType) {
		return sysDictionaryDao.findByProperty("type", dictType, "sort", "asc");
	}

	public SysDictionary getDictByTypeAndVlaue(String dictType, String value) {
		return sysDictionaryDao.getUnique("from SysDictionary t where t.type=?0 and t.value=?1", dictType, value);
	}

	/**
	 * 方法描述: 根據字典类型查出唯一標識
	 * 
	 * @Return
	 **/
	public SysDictionary getUniqueDictByType(String dictType) {
		return sysDictionaryDao.getUnique("from SysDictionary t where t.type=?0", dictType);
	}

	public SysDictionary getUniqueDictByTypeAndCode(SysDictionary dict) {
		return sysDictionaryDao.getUnique("from SysDictionary t where t.type=?0 and codeUniq=?1", dict.getType(),
				dict.getCodeUniq());
	}

	/**
	 * 方法描述: 通过类型和標識查询值
	 * 
	 * @Return
	 **/
	public SysDictionary getDictByTypeAndLabel(String dictType, String label) {
		return sysDictionaryDao.getUnique(
				"from SysDictionary t where t.type=?0 and t.label=?1 and rownum=1  order by t.sort", dictType, label);
	}
}
